package inventoryservicelogic

import (
	"context"
	"property_service/dao/model"
	"property_service/dao/query"
	"property_service/internal/svc"
	"property_service/property_service"
	"property_service/utils/BeanUtils"
	"property_service/utils/result"

	"github.com/zeromicro/go-zero/core/logx"
)

type InventoryAssetReceiptEditLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewInventoryAssetReceiptEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InventoryAssetReceiptEditLogic {
	return &InventoryAssetReceiptEditLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// InventoryAssetReceiptEdit 更新资产入库表
func (l *InventoryAssetReceiptEditLogic) InventoryAssetReceiptEdit(in *property_service.InventoryAssetReceipt) (*property_service.Response, error) {
	// 获取资产入库表模型的查询构造器
	m := query.Use(l.svcCtx.Gorm).InventoryAssetReceipt
	// 构建查询条件：根据ID查询
	do := m.WithContext(l.ctx).Where(m.ID.Eq(in.ID))
	// 执行更新操作，仅更新指定字段，不包含ID、TenantID、StockID、UpdatedAt、CreatedAt
	if _, err := do.UpdateColumns(&model.InventoryAssetReceipt{
		ReceiptCode:            in.ReceiptCode,                          // 入库单号
		ReceiptDate:            BeanUtils.GetDateFormat(in.ReceiptDate), // 入库日期
		EquipmentSource:        in.EquipmentSource,                      // 设备来源
		Receiver:               in.Receiver,                             // 验收人
		Warehouse:              in.Warehouse,                            // 库房
		Supplier:               in.Supplier,                             // 供应商
		SupplierID:             in.SupplierID,                           //供应商id
		Purchaser:              in.Purchaser,                            // 采购员
		ContractNumber:         in.ContractNumber,                       // 合同编号
		InvoiceNumber:          in.InvoiceNumber,                        // 发票号码
		InvoiceDate:            BeanUtils.GetDateFormat(in.InvoiceDate), // 发票日期
		DepreciationMethod:     in.DepreciationMethod,                   // 折旧方法
		DepreciationMethodCode: in.DepreciationMethodCode,               // 折旧方法Code
		AssetUse:               in.AssetUse,                             // 资产用途
		AssetUseCode:           in.AssetUseCode,                         //资产用途Code
		ReceiptMethodCode:      in.ReceiptMethodCode,                    //入库方式Code
		ReceiptMethod:          in.ReceiptMethod,                        // 入库方式
		InstallationNumber:     in.InstallationNumber,                   // 安装单号
		PurchaseID:             in.PurchaseID,                           // 采购申请单ID
		PurchaseCode:           in.PurchaseCode,                         // 采购編碼
		StatusID:               in.StatusID,                             // 状态ID
		UpdatedAtuser:          in.UpdatedAtuser,                        // 更新用户
	}); err != nil {
		// 如果更新失败，返回错误响应
		return result.Err(err).Ed()
	}
	// 更新成功，返回成功响应
	return result.Suc().EditEd()
}
